package com.bocaizp.operation.service.impl;

import com.bocaizp.operation.mapper.HomeMapper;
import com.bocaizp.operation.service.HomeService;
import com.bocaizp.pojo.DTO.GoodJobDTO;
import com.bocaizp.pojo.DTO.PositionDirectionDTO;
import com.bocaizp.pojo.DTO.PositionFatherDTO;
import com.bocaizp.pojo.VO.HomeGoodJobVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Author : huang jie
 * Date : 2024/5/6 22:30
 **/
@Service
public class HomeServiceImpl implements HomeService {

	@Autowired
	private HomeMapper homeMapper;

	/**
	 * 主页职位信息
	 * @return
	 */
	public List<PositionFatherDTO> getPosition() {
		List<PositionFatherDTO> fatherDTOS = homeMapper.getfather();
		for (PositionFatherDTO ss : fatherDTOS){
			List<PositionDirectionDTO> directionDTOS = homeMapper.getDirection(ss.getFather());
			for (PositionDirectionDTO s : directionDTOS){
				List<String> nameList = homeMapper.getName(s.getDirection(), ss.getFather());
				s.setName(nameList);
			}
			ss.setPositionList(directionDTOS);
		}
		return fatherDTOS;
	}

	/**
	 * 精选职位
	 * @return
	 */
	public List<HomeGoodJobVo> getGoodJob() {
		List<HomeGoodJobVo> homeGoodJobVos = new ArrayList<>();
		List<String> industryList = homeMapper.getindustry();
		for (String in : industryList){
			HomeGoodJobVo homeGoodJobVo = new HomeGoodJobVo();
			GoodJobDTO GoodJobVo = homeMapper.getHotJob(in);
			if(GoodJobVo == null){
				break;
			}
			BeanUtils.copyProperties(GoodJobVo, homeGoodJobVo);
			String salary = backSalary(GoodJobVo.getSalaryBottom(), GoodJobVo.getSalaryTop(), GoodJobVo.getSalaryMonth());
			homeGoodJobVo.setSalary(salary);
			homeGoodJobVos.add(homeGoodJobVo);
		}
		return homeGoodJobVos;
	}

	/**
	 * 薪资计算方法
	 * @param salary_bottom
	 * @param salary_top
	 * @param salary_month
	 * @return
	 */
	public String backSalary(int salary_bottom, int salary_top, int salary_month){
		String s_bottom = salary_bottom / 1000 + "";
		String s_top = salary_top / 1000 + "";
		String s_month = "";
		if(salary_month != 12){
			s_month = "·" + salary_month + "薪";
		}
		return s_bottom + "-" +s_top + "K" + s_month;
	}
}
